<template>
  <div class="test-leancloud">
    <router-link to="http://mokelao.gitee.io/js-leancloud-library/">leancloud-library文档</router-link>
    <el-button @click="handleCreateData">创建对象</el-button>
    <el-button @click="handleDeleteData">删除对象</el-button>
    <el-button @click="handleFetchData">更新对象</el-button>
    <el-button @click="handleGetData">获取对象</el-button>
  </div>
</template>

<script>
import service from '@/services/test';

export default {
  name: 'TestLeancloud',
  data() {
    return {
      type: 'Test',
      cateType: 'Cate_Banner',
    };
  },
  methods: {
    handleCreateData() {
      const { type } = this;
      const data = [
        {
          name: 'banner1',
          url: 'https://vuejs.org/sponsor/',
          school: {
            pointType: 'Cate_Banner',
            name: 'banner1',
          },
        },
      ];
      service.setData(type, data).then((res) => {
        console.log(res);
      });
    },
    handleDeleteData() {
      const { type } = this;
      const objectIds = ['11111112222'];
      service.deleteData(type, objectIds).then((res) => {
        console.log(res);
      });
    },
    handleFetchData() {
      const { type } = this;
      const data = [
        {
          objectId: '1111222222222',
          data: {
            name: 'banner2',
            url: 'https://vuejs.org/sponsor/',
            school: {
              pointType: 'Cate_Banner',
              name: 'banner2',
            },
          },
        },
      ];
      service.setData(type, data).then((res) => {
        console.log(res);
      });
    },
    handleGetData() {
      const parmas = {
        page: 1,
        limit: 20,
        sort: [],
      };
      service.fentchData(parmas).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
